const curQuesInfo = window.storage.getItem('contest/curQuesInfo')
let answerList = window.storage.getItem('contest/answerList')
if (!answerList) {
  answerList = ['']
}
const state = {
  curQuesInfo,
  answerList
}

const mutations = {
  setCurQuesInfo (state, curInfo) {
    state.curQuesInfo = curInfo
    window.storage.setItem('contest/curQuesInfo', curInfo)
  },
  setAnswerList (state, { index, answer }) {
    state.answerList[index] = answer
    if (answer === 0) {} else if (!answer) {
      answer = ''
    } else {
      answer = JSON.stringify(answer)
    }
    state.answerList.splice(index, 1, answer)
    window.storage.setItem('contest/answerList', state.answerList)
  }
}

export default {
  namespaced: true,
  state,
  mutations
}
